angular.module('service.auth', [
    "ngResource",
])
    //获取商店列表
    .service('AuthService', ['$resource', function ($resource) {
        // 获取验证码
        /*this.getcode = function (phone, success_func, error_func) {
            var GetPhoneCode = $resource(uc_baseurl + 'user/sendcode/:acount');
            var acount = "cf_linwenpin";
            GetPhoneCode.get({acount: acount, phone: phone}, success_func, error_func);
        };*/
        //通过电话号码获取用户
        this.getUserByPhone = function(phone){
            var resource = $resource(uc_baseurl + 'user/byname/:phone');
            return resource.get({phone:phone},{});
        };
        //外卖用户注册
        this.register = function (user, success_func, error_func) {
            var UserRegist = $resource(uc_baseurl + 'user/add');
            return UserRegist.save(user, success_func, error_func);
        };
        //注册商户接口
        this.registerMerchant = function(merchant,success_func, error_func){
            var UserRegist = $resource(uc_baseurl + 'usermerchant');
            return UserRegist.save(merchant, success_func, error_func);
        };

      //获取省份
        this.getProvince = function(){
            return $resource("http://api.nonggui8.com/address/province").query();
        };
        //获取城市
        this.getCity = function(provinceId){
            return $resource("http://api.nonggui8.com/address/city/byprovince/:id").query({id:provinceId});
        };
        //获取县
        this.getCounty = function(cityId){
            return $resource("http://api.nonggui8.com/address/county/bycity/:id").query({id:cityId});
        };
        //数网收银员系统接口
        //收银系统用户注册
        this.receiptUser = function(user, success_func, error_func){
            var resource = $resource(receiptUrl + 'user/byphone/:phone');
            return resource.save({phone:user.phone,username:user.name},{}, success_func, error_func);
        };
        //通过手机号码收银系统用户
        this.getReceiptUserByPhone = function(phone){
            var resource = $resource(receiptUrl + 'user/queryuserbyphone/:phone');
            return resource.query({phone:phone},{});
        };
        //通过手机号码获取商户
        this.querymerchbyphone = function(phone){
            var resource = $resource(receiptUrl + 'user/querymerchbyphone/:phone');
            return resource.query({phone:phone},{});
        }
        //生成二维码接口
        this.getqrCode = function(merchid, success_func, error_func){
            var resource = $resource(receiptUrl+"agent/qrcodebymerch/:merchid");
            return resource.get({merchid:merchid}, success_func, error_func);
        };
        //发送短信验证码接口
        this.getCode = function(code,success,error){
            var resource = $resource("http://inner.test.shuwang.info/common/sms/sms/smssend");
            return resource.save(code,success,error);
        };
        //上传到收银系统商户注册
        this.receiptRegister = function (merchant, success_func, error_func) {
            var resource = $resource(receiptUrl + 'merchant');
            return resource.save(merchant, success_func, error_func);
        };
        //获取angetid接口
        this.getByagentid = function(id){
            var resource = $resource(qrcodeurl + 'owner/:id');
            return resource.get({id:id});
        }
        //获取开户状态
        this.getstatusByid = function(id){
            var resource = $resource(receiptUrl + 'agent/get/:id');
            return resource.get({id:id})
        }
        //获取商户审核状态
        this.getdatacomplete = function(id, success_func, error_func) {
            var resource = $resource(receiptUrl + 'merchant/:id');
            return resource.get({id:id}, success_func, error_func);
        }
        //
        this.messgservice = function(code,phone){
             var rightButton = document.querySelectorAll(".button_status");
            console.log(rightButton)
             var context = "注册验证码"+code+",您被邀请成为聚收米扫码商户，打死都不告诉别人！";
             var codeContext = {
                msgcontent:context,
                phone:phone
             };
             this.getCode(codeContext,function(){
                 loadCart(false,"loader",".loader_bac");
                 for(var i=0;i<rightButton.length;i++){
                    rightButton[i].removeAttribute("disabled","disabled");
                    $(rightButton).removeClass("right-button1");
             }
             settime();
             },function(resaon){
                loadCart(false,"loader",".loader_bac");
                alert("获取验证码失败！")
             });
        }
        //获取代理商商户
        this.getmerchByqrcode= function(id){
            var resource = $resource(receiptUrl + 'qrcode/query/:agentcode');
            return resource.get({agentcode:id});
        }
        //merchantconfig表通过merchid获取所属agentid
        this.getagentid = function (merchid) {
            var resource = $resource(receiptUrl+'merchantconfig/get/:merchid');
            return resource.get({merchid:merchid});
        }
        //merchant表通过merchid获取userid
        this.getuserid = function (merchid,successFn,errorFn) {
            var resource = $resource(receiptUrl+'merchant/:merchid');
            return resource.get({merchid:merchid},successFn,errorFn);
        }
        //agent表通过userid获取agentid
        this.getid = function (userid,successFn,errorFn) {
            var resource = $resource(receiptUrl+'agent/getagent/:userid');
            return resource.get({userid:userid},successFn,errorFn);
        }
        //merchant表通过merchid获取商户信息
        this.get_merchinfo = function(merchid,successFn,errorFn){
            var resources = $resource(receiptUrl+'merchant/:merchid');
            return resources.get({merchid:merchid},successFn,errorFn);
        }
    }])